package com.hua.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.hua.entities.Setmeal;
import com.hua.entities.SetmealDish;
import com.hua.entities.SetmealDto;
import com.hua.mapper.SetmealMapper;
import com.hua.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class SetmealServiceImpl extends ServiceImpl<SetmealMapper, Setmeal> implements SetmealService{

    @Autowired
    private SetmealDishServiceImpl service;

    @Transactional
    @Override
    public void savaSetmealAndDish(SetmealDto setmealDto) {
        this.save(setmealDto);
        List<SetmealDish> list = setmealDto.getSetmealDishes();
        list = list.stream().map(item->{
           item.setSetmealId(setmealDto.getId());
           return item;
        }).collect(Collectors.toList());
        service.saveBatch(list);
    }
}
